﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AresCustomYacht
{
	public partial class P_BatchAdd : System.Web.UI.Page
	{
	    readonly BL _bl =  new BL();
		protected void Page_Load(object sender, EventArgs e)
		{
            Utility.DisplayPageMessage(this,lblMessage);
		}

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(dfsData.Text)) return;

            var what = Utility.GetQueryStringItem(this, "What");
            var dataDictionary = new Dictionary<string, string>();
            var lines = dfsData.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            lines.ForEach(p => dataDictionary.Add(p.Split(',')[0].Trim(), p.Split(',')[1].Trim()));
            var parentId = int.Parse(Utility.GetQueryStringItem(this, "ParentId"));
            switch(what)
            {

                case "Division":
                    _bl.AddDivisions(dataDictionary);
                    break;
                case "Trade":
                    _bl.AddDepartments(parentId, dataDictionary);
                    break;
                case "Location":
                    _bl.AddLocations(parentId, dataDictionary);
                    break;
                case "Task":
                    _bl.AddTasks(parentId, dataDictionary);
                    break;

            }

            Response.Redirect("Boats.aspx");

        }
	}
}